﻿using System;
using NUnit.Framework;
using System.Text;
using System.Diagnostics;

namespace HexControlTest
{
	[TestFixture]
	public class HexControlTest
	{
		private HexControl.HexControl _hexControl;

		[SetUp]
		public void setUp()
		{
			Debug.Listeners.Clear();	// to ignore Debug.Assert
			_hexControl = new HexControl.HexControl();
		}

		[Test]
		public void testGetByte()
		{
			string s = "abcdefghijklmnopqrstuvwxyz";
			_hexControl.SetStream(
				Encoding.ASCII.GetBytes(s),
				Encoding.ASCII.GetByteCount(s));

			Assert.AreEqual('e', _hexControl.GetByte(4));
			Assert.AreEqual('j', _hexControl.GetByte(9));
		}

		[Test]
		[ExpectedException(typeof(IndexOutOfRangeException))]
		public void testGetByte_OutOfRange()
		{
			string s = "abcdefghijklmnopqrstuvwxyz";
			_hexControl.SetStream(
				Encoding.ASCII.GetBytes(s),
				Encoding.ASCII.GetByteCount(s));

			_hexControl.GetByte(100);
		}
	}
}
